var express = require('express');
var router = express.Router();
var fileUtil = require('../utils/fileUtils')
let article = require('../middleware/article_mid')
router.post('/img', async (req, res) => {
    let fileName = await fileUtil.upload(req, {fileDir: 'public/article'})
    fileName = 'http://localhost:3000/article/' + fileName
    res.send({errno: 0, data: [fileName]})
})
router.post('/release', async function (req, res) {
    let Userdata = await redisUtils.get("UserloginData")
    let arr = Userdata.split(',');
    let userdata = JSON.parse(arr).id
    req.body.u_id = userdata

    article.Release(req, res)
})
router.get('/getDetails', function (req, res) {
    article.getDetails(req, res)
})
let redisUtils = require('../utils/redisUtils')
router.get('/myHistory', async function (req, res) {
    let Userdata = await redisUtils.get("UserloginData")
    let arr = Userdata.split(',');
    let userdata = JSON.parse(arr).id
    req.u_id = userdata
    article.myHistory(req, res)

})
router.get('/wir', async function (req, res) {
    res.send("ok")
})
//写入评论
router.post('/setComment', async function (req, res) {
    let Userdata = await redisUtils.get("UserloginData")
    let arr = Userdata.split(',');
    let userdata = JSON.parse(arr).id
    req.body.u_id = userdata
    article.setComment(req, res)
})
//获取评论
router.post('/getComment', async function (req, res) {
    article.getComment(req, res)
})

//添加点击量
router.post('/addHist', async function (req, res) {

    article.addHist(req, res)
})
//添加点击量
router.get('/getAll', async function (req, res) {

    article.getAll(req, res);
})

module.exports = router;